/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans;

import entities.Person;
import entities.SubjectMatter;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author corneliugosa
 */
@Stateless
public class SubjectMatterFacade extends AbstractFacade<SubjectMatter> implements SubjectMatterFacadeLocal {
    @PersistenceContext(unitName = "School-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public SubjectMatterFacade() {
        super(SubjectMatter.class);
    }

    @Override
    public SubjectMatter findById(Integer id) {
        SubjectMatter matter = null;
        
        Query query = em.createNamedQuery("SubjectMatter.findById");
        query.setParameter("id", id);
        matter = (SubjectMatter)query.getSingleResult();
        
        return matter;
    }

    @Override
    public List<SubjectMatter> findByClassAndProf(Person proffessor, Integer cls) {
        List<SubjectMatter> list = null;
        
        Query query = em.createNamedQuery("SubjectMatter.findByClassAndProf");
        query.setParameter("cls", cls);
        query.setParameter("proffessor", proffessor);
        list = query.getResultList();
        
        return list;
    }
    
}
